<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Used to escape certain characters</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.db2-escape-string" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">db2_escape_string</h1>
  <p class="verinfo">(PECL ibm_db2 &gt;= 1.6.0)</p><p class="refpurpose"><span class="refname">db2_escape_string</span> &mdash; <span class="dc-title">
   Used to escape certain characters
  </span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.db2-escape-string-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>db2_escape_string</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$string_literal</code></span>
   ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   Prepends backslashes to special characters in the string argument.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.db2-escape-string-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">string_literal</code></dt>

     <dd>

      <p class="para">
       The string that contains special characters that need to be modified. 
       Characters that are prepended with a backslash are <em>\x00</em>, 
       <em>\n</em>, <em>\r</em>, <em>\</em>, 
       <em>&#039;</em>, <em>&quot;</em> and <em>\x1a</em>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.db2-escape-string-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <code class="parameter">string_literal</code> with the special characters 
   noted above prepended with backslashes.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.db2-escape-string-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1242">
    <p><strong>Example #1 A <span class="function"><strong>db2_escape_string()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     Result of using the <span class="function"><strong>db2_escape_string()</strong></span> function
    </p></div>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">"All&nbsp;characters:&nbsp;\x00&nbsp;,&nbsp;\n&nbsp;,&nbsp;\r&nbsp;,&nbsp;\&nbsp;,&nbsp;'&nbsp;,&nbsp;\"&nbsp;,&nbsp;\x1a&nbsp;."</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">"Backslash&nbsp;(\).&nbsp;Single&nbsp;quote&nbsp;(').&nbsp;Double&nbsp;quote&nbsp;(\")"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">"The&nbsp;NULL&nbsp;character&nbsp;\0&nbsp;must&nbsp;be&nbsp;quoted&nbsp;as&nbsp;well"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">3</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">"Intersting&nbsp;characters:&nbsp;\x1a&nbsp;,&nbsp;\x00&nbsp;."</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">4</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">"Nothing&nbsp;to&nbsp;quote"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">5</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">200676</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">6</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;foreach(&nbsp;</span><span style="color: #0000BB">$str&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$string&nbsp;</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"db2_escape_string:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">db2_escape_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">).&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
db2_escape_string: All characters: \0 , \n , \r , \\ , \&#039; , \&quot; , \Z .
db2_escape_string: Backslash (\\). Single quote (\&#039;). Double quote (\&quot;)
db2_escape_string: The NULL character \0 must be quoted as well
db2_escape_string: Intersting characters: \Z , \0 .
db2_escape_string: Nothing to quote
db2_escape_string: 200676
db2_escape_string:
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.db2-escape-string-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="db2_prepare.html" class="function" rel="rdfs-seeAlso">db2_prepare()</a> - Prepares an SQL statement to be executed</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>